package cn.uway.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cn.uway.properties.RedisProperties;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;


@Configuration
public class RedisConfig {
	protected  Logger logger = LoggerFactory.getLogger(this.getClass());	

	@Autowired
	private  RedisProperties redisProperties;
	
	
	@Bean
    public JedisPoolConfig jedisPoolConfig() {  
		
        JedisPoolConfig poolConfig = new JedisPoolConfig();
		poolConfig.setMaxTotal(redisProperties.getMaxTotal());
		poolConfig.setMaxIdle(redisProperties.getMaxIdle());
		poolConfig.setMinIdle(redisProperties.getMinIdle());	       
		poolConfig.setMaxWaitMillis(redisProperties.getMaxWaitMillis());
		poolConfig.setTestOnBorrow(true);
		poolConfig.setTestOnReturn(true);
	    return poolConfig;  
    }  
	 
	
	@Bean
	public JedisPool jedisPool() {  
	     return new JedisPool(jedisPoolConfig(), redisProperties.getHost(), redisProperties.getPort(), 
	    		 redisProperties.getTimeout(), redisProperties.getPassword());  
	}  
	     	
	
}
